/*
 * @Author: your name
 * @Date: 2022-02-14 20:36:15
 * @LastEditTime: 2022-02-15 08:19:30
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue3.2\src\i18n\index.js
 */
import {
  createI18n
} from 'vue-i18n'
import CN from './zh'
import EN from './en'

const messages = {
  en: {
      ...EN
  },
  zh: {
      ...CN
  }
}

const getCurrentLanguage = () => {
  const UAlang = navigator.language
  const language = UAlang.indexOf('zh') !== -1 ? 'zh' : 'en'
  localStorage.setItem('lang', language)
  return language
}

const i18n = createI18n({
  legacy: false,
  globalInjection: true,
  locale: getCurrentLanguage() || '',
  messages: messages
})

export default i18n
